<style type="text/css">
    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="车牌区域" prop="Visitcontactid">
            <p @click="getCarCityData()" class="select-click">{{personalName}}</p>
            <div v-if="selectPeopelIsShow" class="selected-search">
                <div class="selected-arr">
                    <template v-for="(item,index) in carCityArr">
                        <p @click="choosePeople(item.id,item.code)" class="selected-item">
                            {{item.code}}</p>
                    </template>
                </div>
            </div>
        </Form-item>
        <Form-item label="车牌号" prop="carcode">
            <i-input v-model="formValidate.carcode" placeholder="请输入车牌号"></i-input>
        </Form-item>
        <Form-item label="车辆类型" prop="cartype">
            <i-select v-model="formValidate.cartype" placeholder="请选择车辆类型">
                <template v-for="(item,index) in carTypeArr">
                    <i-option :value="item">{{item}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="联系人" prop="people">
            <i-input v-model="formValidate.people" placeholder="请输入联系人"></i-input>
        </Form-item>
        <Form-item label="联系人电话" prop="phone">
            <i-input v-model="formValidate.phone" placeholder="请输入联系人电话"></i-input>
        </Form-item>
        <Form-item label="编号" prop="cardno">
            <i-input v-model="formValidate.cardno" placeholder="请输入编号"></i-input>
        </Form-item>
        <Form-item label="状态" prop="state">
            <i-select v-model="formValidate.state" placeholder="状态">
                    <i-option value="正常">正常</i-option>
                    <i-option value="退卡">退卡</i-option>
                    <i-option value="离场">离场</i-option>
                    <i-option value="冻结">冻结</i-option>
            </i-select>
        </Form-item>
        <!--<Form-item label="被访问人员" prop="Visitcontactid">-->
        <!--<p @click="getPeopelData()" class="select-click">{{personalName}}</p>-->
        <!--<div v-if="selectPeopelIsShow" class="selected-search">-->
        <!--<div class="search-action">-->
        <!--<i-input v-model="formValidate.Visitcontactid" placeholder="请输入访问部门"></i-input>-->
        <!--</div>-->
        <!--<div class="selected-arr">-->
        <!--<template v-for="(item,index) in principalArr">-->
        <!--<p @click="choosePeople(item.id,item.personalname)" class="selected-item">{{item.personalname}}</p>-->
        <!--</template>-->
        <!--</div>-->
        <!--</div>-->
        <!--</Form-item>-->
        <!--<Form-item label="电话" prop="Visitorphone">-->
        <!--<i-input v-model="formValidate.Visitorphone" placeholder="请输入电话"></i-input>-->
        <!--</Form-item>-->
        <Form-item label="开始时间" >
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" :value="formValidate.expiredatestart" placeholder="选择开始日期" @on-change="changeStartDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="结束时间" >
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" :value="formValidate.expiredateend" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <!--上传图片-->
        <!--<Form-item label="封面" prop="image">-->
        <!--<div class="demo-upload-list" v-for="item in imageList">-->
        <!--<template v-if="item.status === 'finished'">-->
        <!--<img :src="apiUtilBase + item.response.Msg">-->
        <!--<div class="demo-upload-list-cover">-->
        <!--<Icon type="ios-eye-outline" @click="handleView(apiUtilBase + item.response.Msg)"></Icon>-->
        <!--<Icon type="ios-trash-outline" @click="handleRemove(item)"></Icon>-->
        <!--</div>-->
        <!--</template>-->
        <!--<template v-else>-->
        <!--<Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>-->
        <!--</template>-->
        <!--</div>-->
        <!--<Upload ref="upload"-->
        <!--:show-upload-list="false"-->
        <!--:default-file-list="defaultList"-->
        <!--:on-success="handleSuccess"-->
        <!--:format="['jpg','jpeg','png']"-->
        <!--:max-size="2048"-->
        <!--:name="'uploadFile'"-->
        <!--:on-format-error="handleFormatError"-->
        <!--:on-exceeded-size="handleMaxSize"-->
        <!--:before-upload="handleBeforeUpload"-->
        <!--multiplelayout-content-->
        <!--type="drag"-->
        <!--:action="upLoadFile"-->
        <!--style="display: inline-block;width:58px;">-->
        <!--<div style="width: 58px;height:58px;line-height: 58px;">-->
        <!--<Icon type="camera" size="20"></Icon>-->
        <!--</div>-->
        <!--</Upload>-->
        <!--<Modal title="查看图片" v-model="visible">-->
        <!--<img :src="seeImg" v-if="visible" style="width: 100%">-->
        <!--</Modal>-->
        <!--</Form-item>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import carCity from '../../assets/utils/car_city';

    export default {
        data() {
            return {
                carTypeArr: [
                    '大型汽车', '小型汽车', '专用汽车', '特种车', '电瓶车', '三轮摩托车', '二轮摩托车', '四轮农用运输车', '三轮农用运输车',
                ],
                visitorid:'',
                formValidate: {
                    //添加字段
                    carcode: '',
                    cartype: '',
                    people: '',
                    phone: '',
                    cardno: '',
                    expiredatestart: '',
                    expiredateend: '',
                    state:'',
                },
                ruleValidate: {
                    carcode: [
                        {required: true, message: '车牌号', trigger: 'blur'}
                    ],
                    cartype: [
                        {required: true, message: '请选择车辆分类 ', trigger: 'change'}
                    ],
                    people: [
                        {required: true, message: '车辆联系人不能为空', trigger: 'blur'}
                    ],
                    phone: [
                        {required: true, message: '联系人电话不能为空', trigger: 'blur'}
                    ],
                    expiredatestart: [
                        {required: true, type: 'date', message: '请选择时间', trigger: 'change'}
                    ],
                    expiredateend: [
                        {required: true, type: 'date', message: '请选择时间', trigger: 'change'}
                    ],
                },
                papertypeArr: [],
                //被访问人员列表
                principalId: '',
                principalArr: [],
                personalName: '请选择',
                selectPeopelIsShow: false,
                //图片
                defaultList: [],
                imageList: '',
                imagePost: [],
                visible: false,
                seeImg: '',
                upLoadFile: apiUtil.urls.UploadFile,
                apiUtilBase: apiUtil.urls.baseUrl,
                //车辆区域
                carCityArr: [],
            }
        },
        mounted: function () {
            let id = this.$route.query.id;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            changeStartDate: function (date) {
                console.log(date)
                this.formValidate.expiredatestart = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.expiredateend = date;

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            //获取车牌
            getCarCityData() {
                let that = this;

                this.carCityArr = carCity;
                if (this.selectPeopelIsShow) {
                    this.selectPeopelIsShow = false;
                } else {
                    this.selectPeopelIsShow = true;
                }
                console.log('车辆地区:', carCity)
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: id,
                };
                apiUtil.get(that, apiUtil.urls.GetVisitorDetail, para, function (res) {
                    that.$Loading.finish();

                    that.formValidate.people = res.Msg.people;
                    that.formValidate.phone = res.Msg.phone;
                    that.formValidate.cartype = res.Msg.cartype;
                    that.formValidate.carcode = res.Msg.carcode.split('-')[1];
                    that.personalName = res.Msg.carcode.split('-')[0];
                    that.formValidate.state = res.Msg.state;
                    that.formValidate.expiredatestart = res.Msg.expiredatestart;
                    that.formValidate.expiredateend = res.Msg.expiredateend;
                    that.visitorid =res.Msg.visitorid;
                    that.getPaperData();
                    // that.formValidate.state =res.data.state.toString();
                });
            },
            //修改
            updateData: function (model) {
                let that = this;

                model.id = this.$route.query.id;
                model.visitorid = this.visitorid;
                model.carcode = this.personalName + '-' + model.carcode;

                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditVisitorCar, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
